package com.baidu.logindemos.ui.welcome

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.animation.AnimationUtils
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.baidu.logindemos.R
import com.baidu.logindemos.databinding.ActivityWelcomeBinding
import com.baidu.logindemos.ui.main.MVPMainActivity
import com.baidu.logindemos.ui.main.MainActivity

/**
 * 欢迎页
 */
class WelcomeActivity : AppCompatActivity() {
    lateinit var binding: ActivityWelcomeBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityWelcomeBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        binding.nextBtn.setOnClickListener {
            //设置activity动画
            //判断版本号
            startActivity(Intent(this, MVPMainActivity::class.java))
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
                overrideActivityTransition(OVERRIDE_TRANSITION_OPEN,R.anim.anim_right_in, R.anim.anim_left_out)
            }else {
                overridePendingTransition(R.anim.anim_right_in, R.anim.anim_left_out)
            }
        }

    }

    override fun onResume() {
        super.onResume()
        //加载动画
        val upAnim = AnimationUtils.loadAnimation(this,R.anim.text_up_anim)
        val downAnim = AnimationUtils.loadAnimation(this,R.anim.text_down_anim)

        binding.tvUp.startAnimation(downAnim)
        binding.tvDown.startAnimation(upAnim)
    }
}